//
//  TouzhuPopover.m
//  SSC
//
//  Created by 红沙尘 on 17/6/15.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "TouzhuPopover.h"

@interface TouzhuPopover ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *myTableView;
}
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) CGSize contentSize;
@end

@implementation TouzhuPopover

- (id)initWithArray:(NSArray *)array contentSize:(CGSize)contentSize {
    self = [super init];
    
    if (self) {
        self.dataArray = array;
        self.contentSize = contentSize;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.contentSize.width, self.contentSize.height)];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    myTableView.rowHeight = 45;
    myTableView.estimatedRowHeight = 45;
    myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:myTableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PopoverCel"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:@"PopoverCel"];
        cell.textLabel.textColor = Color333333;
        cell.textLabel.font = [MTool fontOfSize:14];
        
    }
    NSString *text = self.dataArray[indexPath.row];
    cell.textLabel.text = [text substringToIndex:text.length - 1];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if ([self.delegate respondsToSelector:@selector(touzhuTypeChanged:index:)]) {
        
        [self.delegate touzhuTypeChanged:cell.textLabel.text index:indexPath.row];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
